<template>
  <div class="generic-data-display">
    <template v-for="(data, key) in dataObjects" :key="key">
      <!-- 详情对象展示 -->
      <div v-if="isDetailObject(data)" class="data-section">
        <h3 class="section-title">
          <i class="el-icon-document"></i>
          {{ getDisplayTitle(key, data) }}
        </h3>
        <!-- 表单风格详情展示 -->
        <el-form label-position="left" label-width="140px" class="detail-form">
          <template v-for="(value, fieldKey) in getDetailData(data)" :key="'detail-' + fieldKey">
            <el-form-item :label="fieldKey">
              <!-- 字典：动态字典渲染 -->
              <template v-if="isDict(value)">
                <DictCellRenderer :value="value" />
              </template>

              <!-- Text：长文本文本域（只读） -->
              <template v-else-if="isText(value)">
                <el-input type="textarea" :model-value="getPlainValue(value)" :rows="4" readonly resize="none" />
              </template>

              <!-- File：文件显示 -->
              <template v-else-if="isFile(value)">
                <div class="file-display flex flex-wrap gap-4">
                  <template v-if="Array.isArray(value.value)">
                    <div
                      v-for="file in value.value"
                      :key="file.url"
                      class="file-card flex flex-col items-center justify-center p-4 border rounded w-[calc(50%-8px)] hoverable"
                    >
                      <el-icon class="file-icon text-3xl mb-2">
                        <Document />
                      </el-icon>
                      <span class="file-name mb-2 text-center break-all">{{ file.name }}</span>
                      <div class="file-actions flex gap-2">
                        <el-button type="primary" size="small" @click="previewFile(file)">预览</el-button>
                        <el-button type="success" size="small" @click="downloadFile(file)">下载</el-button>
                      </div>
                    </div>
                  </template>

                  <!-- 单文件处理 -->
                  <template v-else>
                    <div class="file-card flex flex-col items-center justify-center p-4 border rounded w-full hoverable">
                      <el-icon class="file-icon text-3xl mb-2">
                        <Document />
                      </el-icon>
                      <span class="file-name mb-2">{{ getPlainValue(value) }}</span>
                      <div class="file-actions flex gap-2">
                        <el-button v-if="getPlainValue(value)" type="primary" size="small"
                          @click="previewFile(getPlainValue(value))">预览</el-button>
                        <el-button v-if="getPlainValue(value)" type="success" size="small"
                          @click="downloadFile(getPlainValue(value))">下载</el-button>
                      </div>
                    </div>
                  </template>
                </div>
              </template>

              <!-- 其他：普通输入框（只读） -->
              <template v-else>
                <el-input :model-value="getPlainValue(value)" readonly />
              </template>
            </el-form-item>
          </template>
        </el-form>
      </div>

      <!-- 列表对象展示 -->
      <div v-else-if="isListObject(data)" class="data-section">
        <h3 class="section-title">
          <i class="el-icon-table"></i>
          {{ getDisplayTitle(key, data) }}
        </h3>
        <el-table :data="getListData(data)" border stripe class="data-table">
          <el-table-column label="序号" align="center" width="80">
            <template #default="scope">
              <span>{{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column v-for="colKey in getTableColumns(getListData(data))" :key="colKey" :prop="colKey"
            :label="colKey" :width="getColumnWidth(getListData(data), colKey)"
            :align="getColumnAlign(getListData(data), colKey)" show-overflow-tooltip>
            <template #default="{ row }">
              <DictCellRenderer :value="row[colKey]" :in-table="true" />
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!-- 简单值展示 -->
      <div v-else class="data-section">
        <h3 class="section-title">
          <i class="el-icon-info"></i>
          {{ getDisplayTitle(key, data) }}
        </h3>
        <div class="data-list">
          <div class="data-row">
            <div class="data-label">{{ key }}</div>
            <div class="data-value" :class="getValueStyleClass(data)">
              <DictCellRenderer :value="data" />
            </div>
          </div>
        </div>
      </div>
    </template>

    <!-- 文件预览组件 -->
    <FilePreview v-model="previewVisible" :url="previewUrl" :title="previewTitle" :type="previewType" />
  </div>
</template>

<script setup lang="ts">
import DictTag from '@/components/DictTag/index.vue'
import FilePreview from '@/components/FilePreview/FilePreview.vue'
import { Loading } from '@element-plus/icons-vue'

interface Props {
  data: Record<string, any>
}
const BASE_URL = import.meta.env.VITE_APP_BASE_API
const props = defineProps<Props>()
const { proxy } = getCurrentInstance() as any

// 动态字典缓存
const dictCache = ref<Record<string, any[]>>({})
const dictLoading = ref<Record<string, boolean>>({})

// 文件预览相关状态
const previewVisible = ref(false)
const previewUrl = ref('')
const previewTitle = ref('')
const previewType = ref('')

// 计算属性：获取所有数据对象
const dataObjects = computed(() => {
  const result: Record<string, any> = {}

  Object.keys(props.data).forEach(key => {
    const value = props.data[key]
    if (value !== null && value !== undefined) {
      result[key] = value
    }
  })

  return result
})

// 动态加载字典数据
const loadDictData = async (dictType: string): Promise<any[]> => {
  if (!dictType || !proxy?.useDict) return []

  // 如果正在加载，等待加载完成
  if (dictLoading.value[dictType]) {
    return new Promise((resolve) => {
      const checkLoading = () => {
        if (!dictLoading.value[dictType]) {
          resolve(dictCache.value[dictType] || [])
        } else {
          setTimeout(checkLoading, 50)
        }
      }
      checkLoading()
    })
  }

  // 如果已经缓存，直接返回
  if (dictCache.value[dictType]) {
    return dictCache.value[dictType]
  }

  // 开始加载
  dictLoading.value[dictType] = true

  try {
    const dictObj = proxy.useDict(dictType)
    const dictData = dictObj?.[dictType]

    // 处理不同的字典数据格式
    let resolvedData: any[] = []
    if (Array.isArray(dictData)) {
      resolvedData = dictData
    } else if (dictData?.value && Array.isArray(dictData.value)) {
      resolvedData = dictData.value
    } else if (dictData?._value && Array.isArray(dictData._value)) {
      resolvedData = dictData._value
    }

    dictCache.value[dictType] = resolvedData
    return resolvedData
  } catch (error) {
    console.warn(`Failed to load dict: ${dictType}`, error)
    dictCache.value[dictType] = []
    return []
  } finally {
    dictLoading.value[dictType] = false
  }
}

// 判断是否为详情对象（包含字段的对象）
function isDetailObject(obj: any): boolean {
  if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
    return false
  }

  // 检查是否包含带type字段的对象结构
  const values = Object.values(obj)
  return values.some(value =>
    value &&
    typeof value === 'object' &&
    'type' in value
  )
}

// 判断是否为列表对象（数组或包装后的列表对象）
function isListObject(obj: any): boolean {
  // 如果是包装后的列表对象（包含data属性）
  if (obj && typeof obj === 'object' && obj.data && Array.isArray(obj.data)) {
    return obj.data.length > 0
  }
  // 如果是直接的数组
  return Array.isArray(obj) && obj.length > 0
}

// 获取列表数据
function getListData(obj: any): any[] {
  // 如果是包装后的列表对象，返回data属性
  if (obj && typeof obj === 'object' && obj.data && Array.isArray(obj.data)) {
    return obj.data
  }
  // 如果是直接的数组，直接返回
  return Array.isArray(obj) ? obj : []
}

// 获取详情数据（过滤掉businessTitle字段）
function getDetailData(obj: any): Record<string, any> {
  if (!obj || typeof obj !== 'object') {
    return {}
  }

  const result: Record<string, any> = {}
  Object.keys(obj).forEach(key => {
    // 过滤掉businessTitle字段
    if (key !== 'businessTitle') {
      result[key] = obj[key]
    }
  })

  return result
}

// 获取展示标题
function getDisplayTitle(key: string, data: any): string {
  // 优先使用businessTitle
  if (data && data.businessTitle) {
    return data.businessTitle
  }

  // 兜底使用预设的标题映射
  const titleMap: Record<string, string> = {
    'contractDetail': '合同信息',
    'projectList': '项目列表',
    'userInfo': '用户信息',
    'orderList': '订单列表',
    'productList': '产品列表',
    'paymentList': '支付列表'
  }

  return titleMap[key] || key
}

// 获取表格列
function getTableColumns(data: any[]): string[] {
  if (data.length === 0) return []

  const firstItem = data[0]
  if (typeof firstItem === 'object' && firstItem !== null) {
    return Object.keys(firstItem)
  }

  return []
}

// 列类型推断（优先识别带有 { value, type } 结构）
function inferColumnType(data: any[], colKey: string): string {
  for (let i = 0; i < data.length; i++) {
    const row = data[i]
    if (!row) continue
    const val = row[colKey]
    if (val === null || val === undefined) continue
    if (isObjectWithType(val)) {
      return val.type || 'String'
    }
    const jsType = typeof val
    if (jsType === 'number') return 'BigDecimal'
    if (jsType === 'string') return 'String'
    if (jsType === 'boolean') return 'Boolean'
    return 'String'
  }
  return 'String'
}

// 已移除旧的字典处理函数，使用新的动态字典加载机制

// 根据列类型返回宽度
function getColumnWidth(data: any[], colKey: string): number {
  const type = inferColumnType(data, colKey)
  switch (type) {
    case 'Text':
      return 300
    case 'Dict':
      return 150
    case 'BigDecimal':
    case 'Number':
    case 'Long':
      return 150
    case 'String':
    default:
      return 200
  }
}

// 根据列类型返回对齐方式
function getColumnAlign(data: any[], colKey: string): 'left' | 'center' | 'right' {
  const type = inferColumnType(data, colKey)
  switch (type) {
    case 'Text':
      return 'left'
    default:
      return 'center'
  }
}

// 获取单元格显示值
function getCellDisplayValue(value: any): string {
  if (value === null || value === undefined) {
    return '-'
  }

  // 兼容后端返回的 { value, type, mapping? } 结构
  if (isObjectWithType(value)) {
    if (value.type === 'Dict' && value.mapping && value.value !== undefined && value.value !== null) {
      const key = String(value.value)
      return value.mapping[key] || key
    }
    return value.value !== undefined && value.value !== null ? String(value.value) : '-'
  }

  if (typeof value === 'object') {
    // 普通对象兜底为字符串
    try {
      return JSON.stringify(value)
    } catch (_) {
      return String(value)
    }
  }

  return String(value)
}

// 判断是否为长内容
function isLongContent(value: any): boolean {
  const displayValue = getDisplayValue(value)
  return displayValue && displayValue.length > 50
}

// 获取显示值
function getDisplayValue(value: any): string {
  if (isObjectWithType(value)) {
    // 如果是Dict类型且有映射信息，使用映射后的值
    if (value.type === 'Dict' && value.mapping && value.value) {
      return value.mapping[value.value] || value.value
    }
    return value.value || ''
  }

  if (value === null || value === undefined) {
    return '-'
  }

  return String(value)
}

// 判断是否为包含type属性的对象
function isObjectWithType(value: any): boolean {
  return value &&
    typeof value === 'object' &&
    !Array.isArray(value) &&
    'value' in value &&
    'type' in value
}

// 根据类型获取值样式类
function getValueStyleClass(value: any): string {
  if (isObjectWithType(value)) {
    const type = getFieldType(value)
    return getValueClass(type)
  }

  return 'value-string'
}

// 获取字段类型
function getFieldType(value: any): string {
  if (isObjectWithType(value)) {
    return value.type || 'String'
  }
  return 'String'
}

// 根据类型获取值样式类
function getValueClass(type: string): string {
  const classMap: Record<string, string> = {
    'String': 'value-string',
    'Text': 'value-text',
    'Number': 'value-number',
    'BigDecimal': 'value-number',
    'Date': 'value-date',
    'Boolean': 'value-boolean',
    'Dict': 'value-dict',
    'Long': 'value-number'
  }
  return classMap[type] || 'value-string'
}

// 工具函数：类型判断与取值
function isStructured(value: any): boolean {
  return value && typeof value === 'object' && !Array.isArray(value) && 'type' in value
}
function isDict(value: any): boolean {
  return isStructured(value) && value.type === 'Dict' && !!value.dictType
}
function isText(value: any): boolean {
  return isStructured(value) && value.type === 'Text'
}
function isFile(value: any): boolean {
  return isStructured(value) && value.type === 'File'
}
function getPlainValue(value: any): string {
  if (value === null || value === undefined) return ''
  if (isStructured(value)) {
    // File 类型直接返回数组
    if (value.type === 'File' && Array.isArray(value.value)) {
      return value.value.map((file: any) => file.name || 'unknown').join(', ')
    }
    const v = (value as any).value
    return v === null || v === undefined ? '' : String(v)
  }
  if (typeof value === 'object') {
    try { return JSON.stringify(value) } catch { return String(value) }
  }
  return String(value)
}

// 获取文件类型
function getFileType(fileName: string): string {
  if (!fileName) return 'unknown'

  const ext = fileName.split('.').pop()?.toLowerCase()

  // 图片类型
  if (['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg'].includes(ext || '')) {
    return 'image'
  }

  // PDF类型
  if (ext === 'pdf') {
    return 'pdf'
  }

  // Word类型
  if (['doc', 'docx'].includes(ext || '')) {
    return 'word'
  }

  // Excel类型
  if (['xls', 'xlsx'].includes(ext || '')) {
    return 'excel'
  }

  // PowerPoint类型
  if (['ppt', 'pptx'].includes(ext || '')) {
    return 'powerpoint'
  }

  // 文本类型
  if (['txt', 'md', 'json', 'xml', 'csv'].includes(ext || '')) {
    return 'text'
  }

  return 'unknown'
}

// 预览文件方法
function previewFile(file: any) {
  let fileName = "unknown"
  let fileUrl = ""
  let fullPath = ""
  let fileType = "unknown"
  if (typeof file === "string") {
    console.log("🔹 参数类型：字符串")
    fileUrl = file
    fileName = file.split("/").pop() || "unknown"
  } else if (Array.isArray(file)) {
    console.log("🔹 参数类型：数组")
    if (file.length > 0) {
      const firstFile = file[0]
      console.log("🔹 取数组第一个元素:", firstFile)
      if (firstFile && typeof firstFile === "object") {
        fileName = firstFile.name || "unknown"
        fileUrl = firstFile.url || ""
      }
    } else {
      console.warn("⚠️ 文件数组为空")
    }
  } else if (typeof file === "object" && file !== null) {
    console.log("🔹 参数类型：对象")
    fileName = file.name || "unknown"
    fileUrl = file.url || ""
  } else {
    console.warn("⚠️ 参数类型未知，无法解析")
  }
  // 拼接后端前缀
  if (fileUrl) {
    fullPath = fileUrl.startsWith("http") ? fileUrl : `${BASE_URL}${fileUrl}`
    fileType = getFileType(fileName)
  }
  console.log("🔹 fullPath:", fullPath, "fileType:", fileType)
  previewUrl.value = fullPath
  previewTitle.value = `文件预览 - ${fileName}`
  previewType.value = fileType
  previewVisible.value = true
}

// 下载文件方法
function downloadFile(file: any) {
  let fileName = "download"
  let fileUrl = ""
  if (typeof file === "string") {
    console.log("🔹 参数类型：字符串")
    fileUrl = file
    fileName = file.split("/").pop() || "download"
  } else if (Array.isArray(file)) {
    console.log("🔹 参数类型：数组")
    if (file.length > 0) {
      const firstFile = file[0]
      console.log("🔹 取数组第一个元素:", firstFile)
      if (firstFile && typeof firstFile === "object") {
        fileName = firstFile.name || "download"
        fileUrl = firstFile.url || ""
      }
    } else {
      console.warn("⚠️ 文件数组为空，无法下载")
      return
    }
  } else if (typeof file === "object" && file !== null) {
    console.log("🔹 参数类型：对象")
    fileName = file.name || "download"
    fileUrl = file.url || ""
  } else {
    console.warn("⚠️ 参数类型未知，无法下载")
    return
  }
  if (!fileUrl) {
    console.warn("⚠️ 文件 URL 为空，无法下载")
    return
  }
  // 拼接后端前缀
  const fullPath = fileUrl.startsWith("http") ? fileUrl : `${BASE_URL}${fileUrl}`
  console.log("🔹 下载文件 fullPath:", fullPath, "fileName:", fileName)
  // 创建下载链接
  const link = document.createElement("a")
  link.href = fullPath
  link.download = fileName
  document.body.appendChild(link)
  link.click()
  document.body.removeChild(link)
}


// 字典单元格渲染组件
const DictCellRenderer = defineComponent({
  name: 'DictCellRenderer',
  props: {
    value: {
      type: [String, Number, Object],
      default: null
    },
    inTable: {
      type: Boolean,
      default: false
    }
  },
  setup(props) {
    const dictOptions = ref<any[]>([])
    const loading = ref(false)
    const textExpanded = ref(false) // 控制Text类型的展开状态

    // 判断是否为字典类型
    const isDictType = computed(() => {
      return props.value &&
        typeof props.value === 'object' &&
        !Array.isArray(props.value) &&
        (props.value as any).type === 'Dict' &&
        (props.value as any).dictType
    })

    // 判断是否为结构化对象（包含 value 和 type 字段）
    const isStructuredObject = computed(() => {
      return props.value &&
        typeof props.value === 'object' &&
        !Array.isArray(props.value) &&
        'value' in props.value &&
        'type' in props.value
    })

    // 获取显示值
    const displayValue = computed(() => {
      if (!props.value) return '-'

      // 如果是结构化对象，直接返回 value 字段
      if (isStructuredObject.value) {
        const objValue = (props.value as any).value
        return objValue !== null && objValue !== undefined ? String(objValue) : '-'
      }

      // 如果是普通对象，尝试 JSON 序列化
      if (typeof props.value === 'object') {
        try {
          return JSON.stringify(props.value)
        } catch {
          return String(props.value)
        }
      }

      return String(props.value)
    })

    // 获取字段类型
    const fieldType = computed(() => {
      if (isStructuredObject.value) {
        return (props.value as any).type || 'String'
      }
      return 'String'
    })

    // 判断是否为长文本（超过100字符或包含换行符）
    const isLongText = computed(() => {
      if (!isStructuredObject.value || fieldType.value !== 'Text') return false
      const text = displayValue.value
      return text.length > 100 || text.includes('\n')
    })

    // 获取预览文本（前100个字符）
    const previewText = computed(() => {
      if (!isLongText.value) return displayValue.value
      const text = displayValue.value
      const firstLine = text.split('\n')[0]
      return firstLine.length > 100 ? firstLine.substring(0, 100) + '...' : firstLine + '...'
    })

    // 切换展开状态
    const toggleExpanded = () => {
      textExpanded.value = !textExpanded.value
    }

    // 加载字典数据
    const loadDictOptions = async () => {
      if (!isDictType.value || typeof props.value !== 'object') return

      loading.value = true
      try {
        const dictType = (props.value as any).dictType
        const dictData = await loadDictData(dictType)
        dictOptions.value = dictData || []
      } catch (error) {
        console.warn('Failed to load dict options:', error)
        dictOptions.value = []
      } finally {
        loading.value = false
      }
    }

    // 监听值变化，重新加载字典
    watch(() => props.value, () => {
      if (isDictType.value) {
        loadDictOptions()
      }
    }, { immediate: true })

    return {
      dictOptions,
      loading,
      isDictType,
      isStructuredObject,
      displayValue,
      fieldType,
      textExpanded,
      isLongText,
      previewText,
      toggleExpanded
    }
  },
  render() {
    // 1. 字典类型：显示字典标签
    if (this.isDictType && this.dictOptions.length > 0) {
      return h(DictTag, {
        options: this.dictOptions,
        value: this.displayValue
      })
    }

    // 2. 字典加载中：显示加载状态
    if (this.loading) {
      return h('span', [
        h(Loading, { class: 'is-loading' }),
        ' 加载中...'
      ])
    }

    // 3. Text 类型：区分表格和详情展示
    if (this.isStructuredObject && this.fieldType === 'Text') {
      if (this.inTable) {
        // 表格中：显示省略文本，使用Element Plus的tooltip机制
        return h('span', {
          class: 'text-content-table',
          style: {
            display: 'block',
            overflow: 'hidden',
            textOverflow: 'ellipsis',
            whiteSpace: 'nowrap',
            width: '100%',
            lineHeight: '1.5'
          }
        }, this.displayValue)
      } else {
        // 详情中：可展开的文本显示
        if (this.isLongText) {
          return h('div', {
            class: 'text-content-detail-expandable'
          }, [
            // 文本内容
            h('div', {
              class: 'text-content-body',
              style: {
                whiteSpace: 'pre-wrap',
                wordBreak: 'break-word',
                lineHeight: '1.6',
                marginBottom: '8px',
                transition: 'all 0.3s ease',
                overflow: 'hidden'
              }
            }, this.textExpanded ? this.displayValue : this.previewText),

            // 展开/收起按钮
            h('button', {
              class: 'text-expand-button',
              onClick: this.toggleExpanded,
              style: {
                background: 'none',
                border: 'none',
                color: '#409eff',
                cursor: 'pointer',
                fontSize: '12px',
                padding: '4px 0',
                textDecoration: 'underline'
              }
            }, this.textExpanded ? '收起' : '展开')
          ])
        } else {
          // 短文本直接显示
          return h('div', {
            class: 'text-content-detail',
            style: {
              whiteSpace: 'pre-wrap',
              wordBreak: 'break-word',
              lineHeight: '1.6'
            }
          }, this.displayValue)
        }
      }
    }

    // 4. Number/BigDecimal 类型：添加数字样式
    if (this.isStructuredObject && ['Number', 'BigDecimal', 'Long'].includes(this.fieldType)) {
      return h('span', {
        class: 'number-content',
        style: {
          fontFamily: 'monospace',
          fontWeight: '600',
          color: '#e67e22'
        }
      }, this.displayValue)
    }

    // 5. Date 类型：添加日期样式
    if (this.isStructuredObject && this.fieldType === 'Date') {
      return h('span', {
        class: 'date-content',
        style: {
          color: '#27ae60',
          fontWeight: '500'
        }
      }, this.displayValue)
    }

    // 6. Boolean 类型：添加布尔样式
    if (this.isStructuredObject && this.fieldType === 'Boolean') {
      return h('span', {
        class: 'boolean-content',
        style: {
          color: '#3498db',
          fontWeight: '600'
        }
      }, this.displayValue)
    }

    // 7. 默认：普通文本显示
    return h('span', {
      class: 'default-content'
    }, this.displayValue)
  }
})
</script>

<style scoped>
.generic-data-display {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.data-section {
  margin-bottom: 24px;
  background: #fff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  border-left: 4px solid #409eff;
}

.section-title {
  margin: 0 0 20px 0;
  font-size: 16px;
  font-weight: 600;
  color: #303133;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid #ebeef5;
}

.section-title i {
  color: #409eff;
  font-size: 18px;
}

/* 数据列表样式 */
.data-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.data-row {
  display: flex;
  align-items: flex-start;
  padding: 16px 0;
  border-bottom: 1px solid #f0f2f5;
  transition: background-color 0.2s ease;
}

.data-row:last-child {
  border-bottom: none;
}

.data-row:hover {
  background-color: #fafbfc;
  border-radius: 6px;
  margin: 0 -8px;
  padding: 16px 8px;
}

.data-row.long-content {
  flex-direction: column;
  align-items: flex-start;
}

.data-label {
  min-width: 140px;
  max-width: 200px;
  font-weight: 600;
  color: #2c3e50;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  padding: 8px 12px;
  border-radius: 6px;
  margin-right: 16px;
  flex-shrink: 0;
  font-size: 14px;
  border-left: 3px solid #3498db;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.data-row.long-content .data-label {
  margin-right: 0;
  margin-bottom: 8px;
  align-self: flex-start;
}

.data-value {
  flex: 1;
  color: #34495e;
  line-height: 1.6;
  word-break: break-all;
  padding: 8px 12px;
  background: #ffffff;
  border-radius: 6px;
  border: 1px solid #e1e8ed;
  min-height: 36px;
  display: flex;
  align-items: center;
  font-size: 14px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* 数据表格样式 */
.data-table {
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.data-table :deep(.el-table__header) {
  background-color: #f8f9fa;
}

.data-table :deep(.el-table__header th) {
  background-color: #f8f9fa;
  color: #606266;
  font-weight: 600;
  border-bottom: 2px solid #e4e7ed;
}

.data-table :deep(.el-table__row:hover) {
  background-color: #f5f7fa;
}

.data-table :deep(.el-table__row) {
  transition: background-color 0.2s ease;
}

/* 值类型样式 */
.value-string {
  color: #2c3e50;
  background: #ffffff;
}

.value-text {
  color: #2c3e50;
  background: #ffffff;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  min-height: 60px;
  padding: 12px;
}

.value-number {
  color: #e67e22;
  font-weight: 600;
  font-family: 'Courier New', monospace;
  background: linear-gradient(135deg, #fff5e6 0%, #ffe0b3 100%);
  border-left-color: #e67e22 !important;
}

.value-date {
  color: #27ae60;
  font-weight: 500;
  background: linear-gradient(135deg, #e8f5e8 0%, #c8e6c9 100%);
  border-left-color: #27ae60 !important;
}

.value-boolean {
  color: #3498db;
  font-weight: 600;
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
  border-left-color: #3498db !important;
}

.value-dict {
  color: #6c757d;
  font-weight: 500;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-left-color: #6c757d !important;
}

/* 动画效果 */
.data-section {
  animation: fadeInUp 0.4s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.data-row {
  animation: slideInLeft 0.3s ease-out;
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* DictCellRenderer 组件内容样式 */
.data-value :deep(.text-content-detail) {
  min-height: 20px;
  padding: 4px 0;
}

.data-value :deep(.text-content-detail-expandable) {
  min-height: 20px;
  padding: 4px 0;
}

.data-value :deep(.text-expand-button) {
  transition: all 0.2s ease;
}

.data-value :deep(.text-expand-button:hover) {
  color: #66b1ff;
  transform: translateY(-1px);
}

.data-value :deep(.text-content-table) {
  min-height: 20px;
  padding: 2px 0;
}

.data-value :deep(.number-content) {
  font-variant-numeric: tabular-nums;
}

.data-value :deep(.date-content) {
  font-size: 14px;
}

.data-value :deep(.boolean-content) {
  text-transform: capitalize;
}

.data-value :deep(.default-content) {
  color: #34495e;
}

/* 容器：文件列表 */
.file-display {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  width: 100%;
}

/* 每个文件卡片 */
.file-card {
  min-height: 120px;
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
  padding: 12px 16px;
}

/* 悬停或触摸效果只在每个小卡片上生效 */
.file-card.hoverable:hover,
.file-card.hoverable:active {
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
  border-color: #409eff;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(64, 158, 255, 0.15);
}

/* 图标 */
.file-icon {
  color: #409eff;
  font-size: 28px;
  flex-shrink: 0;
}

/* 文件名 */
.file-name {
  color: #2c3e50;
  font-size: 14px;
  font-weight: 500;
  word-break: break-all;
  line-height: 1.4;
  text-align: center;
  margin-bottom: 8px;
}

/* 文件操作按钮 */
.file-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
}


.file-actions .el-button {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.file-actions .el-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .data-section {
    padding: 16px;
  }

  .data-label {
    min-width: 120px;
    max-width: 160px;
  }
}

@media (max-width: 480px) {
  .data-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .data-label {
    min-width: auto;
    max-width: none;
    margin-right: 0;
    margin-bottom: 8px;
    width: 100%;
  }

  .data-value {
    width: 100%;
  }
}
</style>
